<!DOCTYPE html>
<html>
<head>
  <title>地址维护</title>
  <meta name="renderer" content="webkit|ie-comp|ie-stand">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
  <meta http-equiv="Cache-Control" content="no-siteapp" />
  <!-- head 中 -->
  <link rel="stylesheet" th:href="@{/jquery-weui/lib/weui.css}">
  <link rel="stylesheet" th:href="@{/jquery-weui/css/jquery-weui.css}">
  <link rel="stylesheet" th:href="@{/jquery-weui/css/demos.css?t=12}">
  <link rel="stylesheet" th:href="@{/css/h5style.css}">
  <style>
    input::-webkit-input-placeholder, textarea::-webkit-input-placeholder {
      color: #333333;
      font-size: 22px;
    }

    input:-moz-placeholder, textarea:-moz-placeholder {
      color: #333333;
      font-size: 22px;
    }

    input::-moz-placeholder, textarea::-moz-placeholder {
      color: #333333;
      font-size: 22px;
    }

    input:-ms-input-placeholder, textarea:-ms-input-placeholder {
      color: #333333;
      font-size: 22px;
    }
    input{
      height: 55px;
      background:none;
      border:none;
      border-bottom:1px solid #ddd;
      outline: none;
    }
    .weui-cells:before{
      content:" ";
      position:absolute;
      left:0;
      top:0;
      right:0;
      height:1px;
      border-top:none;
      color:#e5e5e5;
      -webkit-transform-origin:0 0;
      transform-origin:0 0;
      -webkit-transform:scaleY(0.5);
      transform:scaleY(0.5);
      z-index:2;
      height: 70px;
    }
    .weui-cells:after{
      content:" ";
      position:absolute;
      left:0;
      bottom:0;
      right:0;
      height:1px;
      border-bottom:none;
      color:#e5e5e5;
      -webkit-transform-origin:0 100%;
      transform-origin:0 100%;
      -webkit-transform:scaleY(0.5);
      transform:scaleY(0.5);
      z-index:2;
    }
    /* 修改标题的文字大小 */
    .weui-dialog__title {
      font-size: 24px;
    }
    .weui-dialog__bd {
      font-size: 20px;
    }
    /* 修改按钮的文字大小和内边距 */
    .weui-dialog__btn {
      font-size: 20px;
      padding: 10px 20px;
    }
    .weui-cell__bd{
      height: 50px;
      line-height: 50px;
    }
    .weui-input{
      height: 50px;
      color: #333333;
      font-size: 22px;
    }
  </style>
</head>

<body class="only-bg-color" ontouchstart style="margin: 0px;">
<form id="form1" name="form1" method="post" action="" autocomplete="off">
  <input type="hidden" name="defaultaddress" id="defaultaddress" value="0">
  <input id="prov_id" name="prov_id" value="" type="hidden">
  <input id="city_id" name="city_id" value="" type="hidden">
  <input id="county_id" name="county_id" value="" type="hidden">
  <div class="page" style="background-color: white">
    <div class="page__hd">
      <div style="height: 20px;"></div>
      &nbsp;&nbsp;&nbsp;<font style="color: #333333;font-weight: bold;font-size: 13pt">
      <span id="bt"></span><!-- 这里根据类型，设置标题 <#if lx == "1">寄件人</#if><#if lx == "2">收件人</#if>信息-->
    </font>
  </div>
  <div class="page__bd">
    <div class="weui-cells" style="margin-top: 0px;border:none">
      <div class="weui-cell">
        <div style="border-right:1px solid gainsboro;" class="weui-cell__bd">
          <input class="weui-input" id="name" name="name" type="text" placeholder="姓名">
        </div>
        <div class="weui-cell__bd">
          <input class="weui-input" name="tel" id="tel" style="margin-left: 10px;" type="number" pattern="[0-9]*" placeholder="电话">
        </div>
      </div>
      <a class="weui-cell weui-cell_access" href="javascript:;" onclick="show_area();">
        <div class="weui-cell__bd">
          <p id="area_p" style="font-size: 22px;">城市/区域</p>
        </div>
        <div id="picktime_text" class="weui-cell__ft" style="color: black;"></div>
      </a>
      <div class="weui-cell">
        <div class="weui-cell__bd">
          <input class="weui-input" name="address" id="address" type="text" placeholder="详细地址（精确到门牌号）">
        </div>
      </div>
      <div class="weui-cell">
        <div class="weui-cell__bd">
          <input class="weui-input" name="grouplabel" id="grouplabel" type="text" placeholder="公司名称（选填）">
        </div>
      </div>
      <div class="weui-cell" style="font-size:10pt;">
        <div class="weui-cell__bd" style="line-height: 50px;">
          <img id="is_check_img" src="/stamp/image/ico/nocheck.png" style="vertical-align:middle;display:inline" width="16px">&nbsp;<span style="font-size: 22px;vertical-align:middle">设为默认地址</span>
        </div>
        <div class="weui-cell__ft"  id="clearInfo"></div>
      </div>
    </div>
  </div>
  </div>
  <div style="height: 5px;"></div>
  <div style="width: 100%;background-color: white;text-align: center;height: 76px;padding-top: 2px">
    <a href="javascript:;" class="weui-btn weui-btn_mini weui-btn_primary" onclick="on_save();" style="height: 45px;font-size: 18px">确&nbsp;定</a>&nbsp;
    <a href="javascript:;" class="weui-btn weui-btn_mini weui-btn_default" onclick="on_back();" style="height: 45px;font-size: 18px">返&nbsp;回</a>
  </div>
  <div style="height: 60px;">&nbsp;</div>
</form>
</body>
<!-- body 最后 -->
<script type="text/javascript" th:src="@{/jquery-weui/lib/jquery-2.1.4.js}" charset="utf-8"></script>
<script type="text/javascript" th:src="@{/jquery-weui/lib/fastclick.js}" charset="utf-8"></script>
<script type="text/javascript" th:src="@{/jquery-weui/js/jquery-weui.js}" charset="utf-8"></script>
<script type="text/javascript" th:src="@{/jsfiles/crypto-js.min.js?t=1}" charset="utf-8"></script>
<script type="text/javascript" th:src="@{/jsfiles/com.js?t=12}" charset="utf-8"></script>
<script th:src="@{/jquery-weui/js/city-picker.min.js}"></script>
<script th:src="@{/layer/mobile/layer.js}" charset="utf-8"></script>
<script>
  $(function() {
    FastClick.attach(document.body);
  });
  var adminUrl = "[[${adminUrl}]]";
  //后端地址
  var url = "[[${serverUrl}]]/stamp/h5/api/";
  //图片显示
  var url1 = "[[${serverUrl}]]/stamp/tp/";
  var lx = "[[${lx}]]";
  var callback = "[[${callback}]]";
  var dz = window.location.href;
  dz = dz.replace(/&/g, "$");

  /*省市区选择*/
  var b;
  function show_area()
  {
    var prov_id = $("#prov_id").val();
    var city_id = $("#city_id").val();
    var county_id = $("#county_id").val();
    //页面层
    b = layer.open({
      type: 1
      ,content: "<iframe width=\"100%;\" id=\"area_iframe\" height=\"600px;\" style=\"border:none;\" src=\""+adminUrl+"/h5/addr/area?prov="+prov_id+"&city="+city_id+"&county="+county_id+"\" scrolling=\"no\"></iframe>"
      ,anim: 'up'
      ,style: 'position:fixed; bottom:0; left:0; width: 100%; height: 600px; border:none;'
    });
  }
  function set_area(lsh,lsh1,lsh2,str)
  {
    $("#area_p").html(str);
    $("#prov_id").val(lsh);
    $("#city_id").val(lsh1);
    $("#county_id").val(lsh2);
    layer.close(b);
  }
  function close_area()
  {
    layer.close(b);
  }
  /*同意按钮切换*/
  var toggle = true;
  $("#is_check_img").click(function() {
    if (toggle) {
      $("#is_check_img").attr("src", "/stamp/image/ico/nocheck.png");
      $("#defaultaddress").val("0");
      toggle = false;
    } else {
      $("#is_check_img").attr("src", "/stamp/image/ico/check.png");
      $("#defaultaddress").val("1");
      toggle = true;
    }
  });
  function on_result(result,msg)
  {
    if (result*1==1)    //成功，返回
    {
      $.toptip(msg, 1000, 'success');
    }
    else{
      $.toptip(msg, 1000, 'error');
    }
  }
  function set_addr(name,tel,address,lsh,lx)
  {
    parent.set_addr(name,tel,address,lsh,lx)
  }
  function on_back(){
    if (callback=="orderadd")    //直接关闭
    {
      parent.$.closePopup();
    }
    else
      window.location.href=adminUrl+"/h5/addr/query?lx=2";
  }
  function on_save(){
    if ($("#name").val()=="")
    {
      $.toptip('姓名不能为空', 1000, 'warning');
      return;
    }
    if ($("#tel").val()=="")
    {
      $.toptip('电话不能为空', 1000, 'warning');
      return;
    }
    if ($("#county_id").val()=="")
    {
      $.toptip('省市区不能为空', 1000, 'warning');
      return;
    }
    if ($("#address").val()=="")
    {
      $.toptip('地址不能为空', 1000, 'warning');
      return;
    }
    psot_get_nonce_h5("addr_add",url+"getnonce",onDo)
  }

  function onDo(nonce_zhi){
    //获取提交令牌
    if (is_null(nonce_zhi)){
      $.alert("没有获取到操作凭证！请重试！");
      return false;
    }
    var jsonData = {
      lx: lx,
      address: $("#address").val(),
      name: $("#name").val(),
      tel: $("#tel").val(),
      prov_id: $("#prov_id").val(),
      city_id: $("#city_id").val(),
      county_id: $("#county_id").val(),
      defaultaddress: $("#defaultaddress").val(),
      grouplabel: $("#grouplabel").val(),
      nonce_ms:"addr_add",
      nonce_zhi:nonce_zhi,
      timestamp:new Date().getTime()
    };
    var sendStr = {
      data:encrypt_str(JSON.stringify(jsonData),localStorage.getItem("a_h5"),localStorage.getItem("b_h5"))
    };
    $.showLoading("地址保存中...");
    $.ajax({
      type:"post",
      url:url+"addr_save",
      data:JSON.stringify(sendStr),
      dataType:"json",
      timeout : 10*1000, //超时时间设置，单位毫秒
      crossDomain: true,
      contentType: 'application/json;charset=UTF-8',
      headers: {
        "token": localStorage.getItem("token_h5"),
      },
      beforeSend: function(request) {
        request.setRequestHeader("X-Requested-With", "XMLHttpRequest");
      },
      success:function(result){
        if (result.code==6) window.location.href = adminUrl+"/h5/login?backurl=" + encodeURIComponent(dz);
        if (result.code==0){
          let rtn = decrypt_str(result.data,localStorage.getItem("a_h5"),localStorage.getItem("b_h5"));
          console.info("rtn:"+rtn);
          let d = JSON.parse(rtn);
          set_addr(d.tWxAddressBook.name,d.dh,d.tWxAddressBook.fullAddress,d.tWxAddressBook.lsh,lx);
        }else{
          $.alert(result.msg);
        }
      },
      error:function(result){
        $.alert("发生错误！");
      },complete:function(res){
        $.hideLoading();
      }
    });
    return false;
  }

</script>

</body>
</html>
